import { goodsForOrder } from "../../../data/goods";
const app=getApp();
Page({
  data: {
    isLoading:true,
    tabActive: 1,
    tabs: ['全部','待付款','待发货','待收货','已完成'],
    orders: [
      {code:'44022919920338473',group:1,goods:goodsForOrder(2)},
      {code:'44022919920338473',group:1,goods:goodsForOrder(3)},
      {code:'44022919920334573',group:2,goods:goodsForOrder(2)},
      {code:'44022919920338907',group:3,goods:goodsForOrder(2)},
      {code:'44022919920332213',group:4,goods:goodsForOrder(2)},
      {code:'44022919920338907',group:4,goods:goodsForOrder(2)}
    ],
    currentOrders:[]
  },
  onLoad(option) {
    if(option.from=='commit'){
      let orders=this.data.orders;
      orders.push({code:'44022919960358444',group:2,goods:app.gData.goodsForCommit});
      orders=orders.sort((a,b)=>a.group>b.group?1:-1);
      this.setData({orders:orders,tabActive:2});
    }
    if(option.tab_active){
      this.setData({tabActive:option.tab_active});
    }
    this.onTabChange();
  },
  onTabChange(e) {
    //wx.pageScrollTo({scrollTop: 0});
    this.setData({isLoading:true});
    let index=e?e.detail.index:this.data.tabActive;
    if(index==0){
      this.setData({currentOrders:this.data.orders});
    }else{
      this.setData({currentOrders:this.data.orders.filter(item=>item.group==index)});
    }
    setTimeout(()=>{
      this.setData({isLoading:false});
    },200);
  },
  onGroupTab(e) {
    //console.log('onGroupTab:',e);
    let name=e.detail.name;
    if(name=='评价') {
      app.gData.goodsForRefund=this.data.currentOrders[e.detail.index].goods;
      wx.navigateTo({url: '/pages/usercenter/send-comment/index',});
    }else{
      wx.showToast({title: name,});
    }
  }
})